#include "common.h"
#include "object.h"

#include "asset.h"
#include "mesh.h"
#include "effect.h"
#include "body.h"
#include "assetmanager.h"

IMPLEMENT_RTTI( Body, Asset )

Body::Body( const std::string& name )
:	Asset( name )
,	_commonFx( NULL )
,	_commonMaterial( NULL )
{
	D3DXMatrixIdentity( &_matObject );
}

Body::~Body()
{
	if( _commonMaterial )
	{
		delete _commonMaterial;
		_commonMaterial = NULL;
	}
	if( !_skins.empty() )
	{
		std::vector< Skin* >::iterator it = _skins.begin();
		for( ; it != _skins.end(); ++it )
		{
			delete ( *it );
		}
		_skins.clear();
	}
}

Body* Body::Create( const std::string& name )
{
	if( AssetManager::Find( name ) )
	{
		return AssetManager::GetBody( name );
	}

	Body* pBody = new Body( name );
	AssetManager::Register( name, pBody );
	return pBody;
}